package cn.myschool.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author oldliu
 * @since 1.0
 */
//@Component
public class SpringUtil /*implements ApplicationContextAware*/ {
//    private static ApplicationContext applicationContext; // Spring应用上下文环境
//
//    @Override
//    public void setApplicationContext(ApplicationContext applicationContext)   {
//        //System.out.println(applicationContext+"??????????????");
//        SpringUtil.applicationContext = applicationContext;
//    }
//
//    public static ApplicationContext getApplicationContext() {
//        return applicationContext;
//    }
//
//    @SuppressWarnings("unchecked")
//    public static <T> T getBean(String name)   {
//        return (T) applicationContext.getBean(name);
//    }
//
//    @SuppressWarnings("unchecked")
//    public static <T> T getBean(Class<?> clz)   {
//        return (T) applicationContext.getBean(clz);
//    }

    private static ApplicationContext ac=new ClassPathXmlApplicationContext("ssm.xml");
    private SpringUtil(){}

    public static <T> T getBean(Class<T> t){
        return ac.getBean(t);
    }
    public static Object getBean(String id){
        return ac.getBean(id);
    }
}
